--redis keys
-- ]; --Lua下表从1开始
-- ];
-- ];
--redis args
-- ]);
-- ]);
-- ]);
-- ];
-- ];

-- 用户每天可领券的最大数量
local user_today_got = redis.call("hget", "user_today_got_key", "u001");
if(user_today_got and tonumber(user_today_got) >= 1) then
-- ; --fail
return -1
end

-- 用户可领券的最大数量
local user_got = redis.call("hget","user_got_key","couponId001");
if(user_got and tonumber(user_got) >= 2) then
-- ; --fail
return -2
end

-- 券的最大数量
local total_got = redis.call("hget","total_got_key","couponId001");
if(total_got and tonumber(total_got) >= 5) then
-- ; --fail
return -3
end

redis.call("hset", "user_today_got_key", "u001", user_today_got+1);
-- redis.call();
-- redis.call();
-- ; -- success
return 1